#ifndef __MESSAGE_H
#define __MESSAGE_H



//stm32  小端模式
#include "msgdef.h"
                                   

typedef union //
{    
    unsigned long msg32;
    struct
    {
//        unsigned char id;
//        unsigned char type;
//        unsigned char val;//
//		unsigned char state;
		
        
        
		unsigned char state;
		unsigned char val;
		unsigned char id;//
		unsigned char type;
//		
		
				
		
		
//		unsigned char type;
//		unsigned char id;//
//		unsigned char val;
//		unsigned char state;
    }umsg32;
}t_msg;


#define drv_packed(type,id,val,state)    	((((unsigned long)(state<<24))&0xff000000)|\
												(((unsigned long)(val<<16))&0x00ff0000)|\
												(((unsigned long)(id<<8))&0x0000ff00)|\
												(((unsigned long)(type))&0x000000ff))												
/*												
#define drv_packed(type,id,val,state)    	((((unsigned int)(type<<24))&0xff000000)|\
												(((unsigned int)(id<<16))&0x00ff0000)|\
												(((unsigned int)(val<<8))&0x0000ff00)|\
												(((unsigned int)(state))&0x000000ff))
	*/

/*
												
#define drv_packed(state,val,id,type)    	((((unsigned int)(type<<24))&0xff000000)|\
												(((unsigned int)(id<<16))&0x00ff0000)|\
												(((unsigned int)(val<<8))&0x0000ff00)|\
												(((unsigned int)(state))&0x000000ff))

*/
/*
												
#if 0
typedef union //
{    
    unsigned int msg32;//这个用来保存取出来的消息值
    struct
    {
		unsigned short int spec; //附加信息，AD值低8位(bit0~bit7)
		unsigned char val;//长按，短按，双击，AD值高8位，编码器正反转信息，(bit8~bit15)
		unsigned char id:4;//表示第几个按键、第几个AD值、第几个编码器消息(bit16~bit23)
		unsigned char type:4;//表示是按键消息、AD消息、编码器消息,TapTemp消息中的哪一类(bit24~bit31)
    }u32;
}t_msg;


#define drv_packed(type,id,val,spec)    ((((unsigned int)(type<<28))&0xf0000000)|\
                                        (((unsigned int)(id<<24))&0x0f000000)|\
                                        (((unsigned int)(val<<16))&0x00ff0000)|\
                                        (((unsigned int)(spec))&0x0000ffff))

#elif 0
typedef union //
{
	unsigned int msg32;//这个用来保存取出来的消息值
	struct
	{
		unsigned  int spec : 12;
		unsigned  int val : 12;
		unsigned  int  id : 4;//表示第几个按键、第几个AD值、第几个编码器消息(bit16~bit23)
		unsigned  int  type : 4;//表示是按键消息、AD消息、编码器消息,TapTemp消息中的哪一类(bit24~bit31)
	}u32;
}t_msg;



#define drv_packed(type,id,val,spec)    ((((unsigned int)(type<<28))&0xf0000000)|\
                                        (((unsigned int)(id<<24))&0x0f000000)|\
                                        (((unsigned int)(val<<12))&0x00fff000)|\
                                        (((unsigned int)(spec))&0x00000fff))
										
#elif 0									
typedef union //
{    
    unsigned int msg32;//这个用来保存取出来的消息值
    struct
    {
		unsigned char state;
		unsigned char spec; //附加信息，AD值低8位(bit0~bit7)
		unsigned char val;//长按，短按，双击，AD值高8位，编码器正反转信息，(bit8~bit15)
		unsigned char id:4;//表示第几个按键、第几个AD值、第几个编码器消息(bit16~bit23)
		unsigned char type:4;//表示是按键消息、AD消息、编码器消息,TapTemp消息中的哪一类(bit24~bit31)
    }umsg32;
}t_msg;


#define drv_packed(type,id,val,spec,state)    	((((unsigned int)(type<<28))&0xf0000000)|\
												(((unsigned int)(id<<24))&0x0f000000)|\
												(((unsigned int)(val<<16))&0x00ff0000)|\
												(((unsigned int)(spec<<8))&0x0000ff00)|\
												(((unsigned int)(state))&0x000000ff))

#elif 1
typedef union //
{    
    unsigned int msg32;
    struct
    {
        unsigned char id:4;
        unsigned char type:4;
        unsigned char val;//
		unsigned char spec; //
		unsigned char state;
    }umsg32;
}t_msg;


#define drv_packed(type,id,val,spec,state)    	((((unsigned int)(type<<28))&0xf0000000)|\
												(((unsigned int)(id<<24))&0x0f000000)|\
												(((unsigned int)(val<<16))&0x00ff0000)|\
												(((unsigned int)(spec<<8))&0x0000ff00)|\
												(((unsigned int)(state))&0x000000ff))


#endif

*/


#define MSGBUFF_SIZE 10

											/*
//#define drv_packed(type,id,val,spec)    ((((unsigned int)(type<<28))&0xf0000000)|\
//                                        (((unsigned int)(id<<24))&0x0f000000)|\
//                                        (((unsigned int)(val<<8))&0x00ff0000)|\
//                                        (((unsigned int)(spec))&0x0000ffff))

//#define drv_packed(type,id,val,spec)    ((((unsigned int)(type<<28))&0xf0000000)|\
//                                        (((unsigned int)(id<<24))&0x0f000000)|\
//                                        (((unsigned int)(val<<16))&0x00ff0000)|\
//                                        (((unsigned int)(spec))&0x0000ffff))

*/


void MsgInit(void);
void WriteMsg(unsigned long msg);
unsigned long ReadMsg(void);

//unsigned  int* ReadMsg(void);
void ClearMsg(void);





//void TouchProcMsgInit(void);
//void TouchProcWriteMsg(unsigned int msg);
//unsigned int TouchProcReadMsg(void);
//void TouchProcClearMsg(void);




#endif




